<?php

namespace app\api\model;

use think\Model;


class QuestionModel extends Model
{
    // 表名
    protected $name = 'rexam_question';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'typedata_text',
        'judgedata_text'
    ];


    public function getTypedataList()
    {
        return ['1' => __('Typedata 1'), '2' => __('Typedata 2'), '3' => __('Typedata 3')];
    }

    public function getJudgedataList()
    {
        return ['0' => __('Judgedata 0'), '1' => __('Judgedata 1')];
    }


    public function getTypedataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['typedata']) ? $data['typedata'] : '');
        $list = $this->getTypedataList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getJudgedataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['judgedata']) ? $data['judgedata'] : '');
        $list = $this->getJudgedataList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getOptionsAttr($val)
    {
        return json_decode($val,true);
    }


}